local log = require('modules.commhm.log')
local uu  = require('modules.commhm.utils')
local ns_config    = require("modules.business_welfare.welfare_config")
local ngx = ngx
local os = os


local FOO = {}


FOO.record = function(filename, api, params, type_, ext_)
    if not params or not api then
        return
    end
    local record = {}
    record.uin              = ngx.ctx.m_params.uin
    record.platform         = ngx.ctx.m_params.platform
    record.channel  		= ngx.ctx.m_params.apiid
    record.login_channel    = ngx.ctx.m_params.platid or ngx.ctx.m_params.apiid
    record.version  		= ngx.ctx.m_params.ver
    record.country  		= ngx.ctx.m_params.country
    record.language 		= ngx.ctx.m_params.lang
    record.ts  	  		    = os.time()
	record.dt  	  		    = os.date("%Y-%m-%d",record.ts)
    record.ip				= ngx.ctx.xff or ngx.var.remote_addr or 'nil'
    record.params           = params        --json格式
    record.api              = api           --埋点接口名称
    record.type             = type_         --可变
    record.ext              = ext_          --可变

    --现网不需要分文件写日志的，filename填写在 ns_config.oplog_not_apart表
    if ns_config.debug ~= 1 and not ns_config.oplog_not_apart[filename] then
        filename = string.format('%s_%s', filename, ngx.worker.id())
    end

    log.day_list_clean(filename, uu.table2json(record))
end


return FOO